import requests
from concurrent.futures import ThreadPoolExecutor
headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
        'Cache-Control': 'no-cache',
        'Connection': 'keep-alive',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'https://gzmh.zwfw.guizhou.gov.cn',
        'Pragma': 'no-cache',
        'Referer': 'https://gzmh.zwfw.guizhou.gov.cn/sxgl/mng/project/check/indexlist?v=1758769330923',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0',
        'X-Requested-With': 'XMLHttpRequest',
        'sec-ch-ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Cookie': 'JSESSIONID=3D73B15B7D54D6E2872CD4BB7F7DF995; _trs_uv=mfufpyxy_367_gwde; tempTokenKey=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLlvKDlhqwiLCJhdWQiOiI2RjY3ODAyQjFFMEE0NzAyODM3RTU1RTA1QTEzRjgyQSIsInNlcnZlciI6Imh0dHBzOi8vZ3ptaC56d2Z3Lmd1aXpob3UuZ292LmNuL2xvZ2luLyIsInJvbGUiOiJST0xFX0FSRUEsUk9MRV9PUkdBTixST0xFX0JVU0lORVNTLFJPTEVfMTIzNDUiLCJpc0luaXRpYWxQYXNzd29yZCI6IjAiLCJyZWdpb25OYW1lIjoi5Yqh5bed5Y6_IiwiaW5kdXN0cnkiOm51bGwsImFwcENvZGUiOiJkZ292LXBvcnRhbCIsIm9yZ2FuTmFtZSI6IuWKoeW3neS7oeS9rOaXj-iLl-aXj-iHquayu-WOv-aUv-WKoeacjeWKoeS4reW_gyIsInJlZ2lvbkNvZGUiOiI1MjAzMjYiLCJpbmR1c3RyeUxpc3QiOm51bGwsIm9yZ2FuQ29kZSI6IjUyMDMyNjk1MjU1NTUiLCJleHBpcmF0aW9uVGltZSI6NjIsImdyYWRlIjoiNCIsInN0YXR1cyI6IjEiLCJpc3MiOiJpbnNwdXIiLCJpYXQiOjE3NTg4NjY5NTksImV4cCI6MTc1ODg5NTc1OX0.KQHtvuwEXBzfG2SWjde-e61rCQFFkYYnnBWcs9uujB1MEM8H3RNCKvpHZk8J7NuSVgYphZmQU640l4pAT6GCTA; userInfoKey={%22role%22:%22ROLE_AREA%2CROLE_ORGAN%2CROLE_BUSINESS%2CROLE_12345%22%2C%22isInitialPassword%22:%220%22%2C%22regionName%22:%22%E5%8A%A1%E5%B7%9D%E5%8E%BF%22%2C%22appCode%22:%22dgov-portal%22%2C%22organName%22:%22%E5%8A%A1%E5%B7%9D%E4%BB%A1%E4%BD%AC%E6%97%8F%E8%8B%97%E6%97%8F%E8%87%AA%E6%B2%BB%E5%8E%BF%E6%94%BF%E5%8A%A1%E6%9C%8D%E5%8A%A1%E4%B8%AD%E5%BF%83%22%2C%22regionCode%22:%22520326%22%2C%22phone%22:%229cc53c7074034faeca5d08332c6448fe%22%2C%22organCode%22:%225203269525555%22%2C%22expirationTime%22:62%2C%22name%22:%22b8d8d995a8cd96ef2209d22c7bf5d36f%22%2C%22id%22:%226F67802B1E0A4702837E55E05A13F82A%22%2C%22email%22:%22%22%2C%22username%22:%22794b0e57b287ba0324891246beaf2855%22%2C%22status%22:%221%22%2C%22isWeakPwd%22:%220%22}; pwdState=true; inspurRoleKey=ROLE_AREA; windowId=43BC184E35CE4B1397E21CD517DB1ECD',
}


def process_item(item):
    """处理单个数据项的请求"""
    try:
        params = {'method': 'cancelUpdate'}
        data = {
            "id": item[0],
            "code": item[1],
            "sign": "second",
            "opinion": "%25E5%2590%258C%25E6%2584%258F"
        }

        response = requests.post(
            'https://gzmh.zwfw.guizhou.gov.cn/sxgl/mng/project/config',
            params=params,
            headers=headers,
            json=data,
        ).json()
        return response
    except :pass


def cancel(data, max_workers=5):
    """使用线程池并发处理所有数据"""
    # 创建线程池，max_workers控制最大并发数
    with ThreadPoolExecutor(max_workers=max_workers) as executor:
        # 提交所有任务到线程池，并获取结果迭代器
        results = executor.map(process_item, data)

        # # 打印所有结果
        # for result in results:
        #     print(result)





def query():

    data = {
        '_search': 'true',
        'nd': '1758866818091',
        'rows': '3000',
        'page': '1',
        'sidx': '',
        'sord': '',
        'name': '',
        'code': '',
        'org_code': '',
        'type': '',
    }

    response = requests.post(
        'https://gzmh.zwfw.guizhou.gov.cn/sxgl/mng/project/check/query',

        headers=headers,
        data=data,
    ).json()
    data = []
    for i in response['rows']:
        data.append([i['cell']['ID'], i['cell']['CODE']])
    print(data)
    return data



# 使用示例
if __name__ == "__main__":
    # 示例数据
    sample_data = query()
    cancel(sample_data, max_workers=3)